﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

using System.IO;
using System.Data;
using System.Data.SqlClient;

namespace Dal
{
    public static class stk
    {
        #region 库房
        public static DataSet stk_stock_query(string strxmldata)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_STOCK_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet stk_stock_save(string strxmldata, string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_STOCK ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);
                dal.AddParameter(sqlcmd, "@type", DbType.String, strtype);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        
        
        #endregion
        #region 查询数据

        #endregion
        #region 成品入库

        public static DataSet STK_CP_RKD_QUERY(string kssj, string  jssj ,string htbh,string strtype,string rklx )
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_CP_RKD_QUERY ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@kssj", DbType.String, kssj);
                dal.AddParameter(sqlcmd, "@jssj", DbType.String, jssj);
                dal.AddParameter(sqlcmd, "@htbh", DbType.String, htbh);
                dal.AddParameter(sqlcmd, "@kffl", DbType.String, strtype);
                dal.AddParameter(sqlcmd, "@RKLX", DbType.String, rklx);
                
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_CP_RKD_data(string appno)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_CP_RKD_data ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
       
                dal.AddParameter(sqlcmd, "@appno", DbType.String, appno);
        
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_CP_RKD_save (string xml)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_CP_RKD_SAVE ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@data", DbType.String, xml);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strappno">单号</param>
        /// <param name="zt">-------0 未审核 1 已审核，3.作废</param>
        /// <returns></returns>
        public static DataSet STK_CP_RKD_CHECK(string strappno, string zt, string shry)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_CP_RKD_CHECK ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, strappno);
                dal.AddParameter(sqlcmd, "@zt", DbType.String, zt);
                dal.AddParameter(sqlcmd, "@shry", DbType.String, shry);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static DataSet STK_CP_RKD_PRINT(string appno)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_CP_RKD_PRINT ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, appno);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
        #region  //公用信息
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strtype"> 0 设计资料 1基础资料</param>
        /// <returns></returns>
        public static DataSet stk_mb_query(string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_MB_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@type", DbType.String, strtype);


                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet Sys_GetStock(string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "select  *  from stk_Stock where ActiveFlag='1' and stockfl=" + strtype;
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.Text);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataSet Sys_GetKs(string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "select  *  from Sys_dept where ActiveFlag='1' and cmn_dept_type=" + strtype;
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.Text);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataSet Sys_Gethtxx()
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_HT_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataSet Sys_GetRYXX()
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_SYS_RYXX";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 半品品出库
        /// <summary>
        /// 半成品出库单
        /// </summary>
        /// <param name="kssj"></param>
        /// <param name="jssj"></param>
        /// <param name="htbh"></param>
        /// <param name="strtype"></param>
        /// <param name="rklx"></param>
        /// <returns></returns>
        public static DataSet STK_BCP_CKD_QUERY(string kssj, string jssj, string htbh, string strtype, string rklx)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_BCP_CKD_QUERY ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@kssj", DbType.String, kssj);
                dal.AddParameter(sqlcmd, "@jssj", DbType.String, jssj);
                dal.AddParameter(sqlcmd, "@htbh", DbType.String, htbh);
                dal.AddParameter(sqlcmd, "@kffl", DbType.String, strtype);
                dal.AddParameter(sqlcmd, "@RKLX", DbType.String, rklx);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
       /// <summary>
       /// 半成品出库单获取数据
       /// </summary>
       /// <param name="appno"></param>
       /// <returns></returns>
        public static DataSet STK_BCP_CKD_data(string appno)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_BCP_CKD_data ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, appno);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static DataSet STK_BCP_CKD_save(string xml)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_BCP_CKD_SAVE ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@data", DbType.String, xml);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strappno">单号</param>
        /// <param name="zt">-------0 未审核 1 已审核，3.作废</param>
        /// <returns></returns>
        public static DataSet STK_BCP_CKD_CHECK(string strappno, string zt, string shry)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_BCP_CKD_CHECK ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, strappno);
                dal.AddParameter(sqlcmd, "@zt", DbType.String, zt);
                dal.AddParameter(sqlcmd, "@shry", DbType.String, shry);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion  
        #region 移库单
        public static DataSet STK_YKD_QUERY(string kssj, string jssj, string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_YKD_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@kssj", DbType.String, kssj);
                dal.AddParameter(sqlcmd, "@jssj", DbType.String, jssj);            
                dal.AddParameter(sqlcmd, "@kffl", DbType.String, strtype);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_YKD_STOCK_DATA(string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_STOCK_DATA_GET";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);        
                dal.AddParameter(sqlcmd, "@stockfl", DbType.String, strtype);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_YKD_STOCK_data(string appno)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_YKD_DATA ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, appno);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_YKD_STOCK_save(string xml)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_YKD_SAVE ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@data", DbType.String, xml);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet STK_YKD_PRINT(string appno)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_YKD_PRINT ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, appno);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static DataSet STK_YKD_CHECK(string strappno, string zt, string shry)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_STK_YKD_CHECK ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);

                dal.AddParameter(sqlcmd, "@appno", DbType.String, strappno);
                dal.AddParameter(sqlcmd, "@zt", DbType.String, zt);
                dal.AddParameter(sqlcmd, "@shry", DbType.String, shry);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
    }
}
